#include "headfile.h"
#include "UserHeadfile.h"
#include "ANO_DT.h"


#pragma section all "cpu0_dsram"
//将本语句与#pragma section all restore语句之间的全局变量都放在CPU0的RAM中

extern uint8 stopcar;

uint32 time0, time1;

uint8 temp = 0;
int core0_main(void)
{
    get_clk();

	//用户在此处调用各种初始化函数等
	module_init();

    //等待所有核心初始化完毕
	IfxCpu_emitEvent(&g_cpuSyncEvent);
	IfxCpu_waitEvent(&g_cpuSyncEvent, 0xFFFF);
	enableInterrupts();

	ui_home();
	lcd_clear(BLACK);
	time0 = systick_getval_ms(STM0);
	while (TRUE)
	{
#ifdef PWM_DISABLE
	    show_img();
#endif

	    ramp_distance = Read_ADC(ADC6, 0);

	    if(!run_start && valid_rowL + valid_rowR < 10 && valid_rowL + valid_rowR > 1){
	        ++temp;
	        if(temp > 50){
	            outlimit = 1;
	        }
	        systick_delay_ms(STM0, 10);
	        if(temp == 1)
	            time1 = systick_getval_ms(STM0);
	    }
	    if(temp && systick_getval_ms(STM0) - time1 > 1000){
	        temp = 0;
        }

	    if(!road_sw && systick_getval_ms(STM0) - road_time > 2000){
	        road_sw = 1;
	    }

#ifndef PWM_DISABLE
	    if(!stopcar && systick_getval_ms(STM0) - time0 > 2000){
	        stopcar |= 0x80;
	    }

	    else if(!finish_sw && systick_getval_ms(STM0) - ignore_time > 1000){
	        finish_sw = 1;
	    }
#endif
	}
}

#pragma section all restore
